function Course (name) {
  this.name = name
  return this
}

Course.prototype.sayName = function (){
  console.log(this.name)
}


// new 函数是实现
function newFunc (origin, ...args) {
  let obj = {}
  obj.__proto__ = origin.prototype
  let obj1= Object.create(origin.prototype)
  let res = origin.call(obj, ...args)
  // return obj
  return typeof res === 'object' ? res : obj
}


const course = newFunc(Course,'lucy')
// console.log(course)
// course.sayName()

// 实现instanceof函数
function judgeInstance (son, origin) {
  while (son) {
    console.log('while innner', son)
    if (son.__proto__ === origin.prototype) {
      return true
    }
    // 如果当前的__proto__和prototype 不相等 则 让子类的__proto__赋值给子类变量 直到为null结束循环
    son = son.__proto__
  }
  console.log('while outer', son)
  return false
}

// console.log(judgeInstance(course, Function))
// console.log(judgeInstance(course, Course))
// console.log(judgeInstance(course, Object))